package shaders;

import helpers.ColorHelper;

import java.awt.Color;
import java.awt.image.BufferedImage;

import javax.vecmath.Vector3d;

import essential.Ray;

public class OrganicShader extends Shader {

	public OrganicShader(){
		per.persistence = 0.85;
		per.n = 16;

		spec = 0.25;
		
		int width = 1000;
		int height = 1000;
		
		textureImage = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
	}
	// Macrobiotic stuff 1st : Color(19,49,16) 2nd : Color(56,159,42) 

	@Override
	public Color calculateColor2d(int x, int y) {

		if(!textureIsSet){
			createTexture();
			textureIsSet = true;
		}
		
		
		return new Color(textureImage.getRGB(x, y));
	}

	@Override
	public Color calculateColor3d(Ray r, Vector3d sp) {

		return Color.red;
	}

	@Override
	public Shader copy() {
		Shader s = new MatteShader();
		this.copyFromTo(this,s);
		return s;
	}

	@Override
	public double fBump(double x, double y, double z) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Color textureColor(double x, double y) {
		double amount = per.perlinNoise(x,y) + per.turbulence(x, y, 2)
						+ 0.5 * per.perlinNoise(0.5*x,0.5*y) + 0.5 * per.turbulence(0.5*x, 0.5*y, 4)
						+ 0.25 * per.perlinNoise(0.25*x,0.25*y) + 0.25 * per.turbulence(0.25*x, 0.25*y, 8);
		//TODO usar   per.persistence = 1.2; per.n = 2;per.stripes(sp.x + 2*per.turbulence(sp.x,sp.y,sp.z), 2.4);
		amount = amount - Math.floor(amount);
		return  ColorHelper.sumColor(
				ColorHelper.mulColor(color, amount),
				ColorHelper.mulColor(gradientColor, 1-amount)
		);		
		
	}



}
